package hu.ikti.oamadmin.beans.service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;

import hu.ikti.oamadmin.beans.BaseBean;
import hu.ikti.oamadmin.types.entities.Service;

@Name("serviceBean")
@Scope(ScopeType.SESSION)
public class ServiceBean extends BaseBean implements Serializable {

	private static final long serialVersionUID = 1L;

	@Out(scope = ScopeType.SESSION)
	private List<Service> serviceList = new ArrayList<Service>();

	@Factory("serviceList")
	public void getServices() {
		List<?> results = entityManager.createQuery(
				"select service from Service service").getResultList();
		if (results != null) {
			serviceList.clear();
			for (Object object : results) {
				serviceList.add((Service) object);
			}
		} else {
			serviceList = new ArrayList<Service>();
		}
	}

}
